// components/promoter-manager-item/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      value: null
    },
    rank: {
      type: Number,
      value: -1
    },
    isLineShow: {
      type: String,
      value: ''
    }
  },

  observers: {
    'item': function (item) {
      this.initGrowthInfo(item);
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    growthInfo: {
      shopGrowthPercent: '',
      incomeGrowthPercent: ''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDetail() {
      this.triggerEvent("detail", null, null);
    },
    // 初始化growthInfo
    initGrowthInfo(item) {
      let shopGrowth = '';
      if (item.shopGrowth >= 0) {
        shopGrowth = '+' + (item.shopGrowth * 100).toFixed(2) + '%';
      } else {
        shopGrowth = '-' + (item.shopGrowth * 100).toFixed(2) + '%';
      }
      let incomeGrowth = '';
      if (item.incomeGrowth >= 0) {
        incomeGrowth = '+' + (item.incomeGrowth * 100).toFixed(2) + '%';
      } else {
        incomeGrowth = '-' + (item.incomeGrowth * 100).toFixed(2) + '%';
      }
      this.setData({
        growthInfo: {
          ...this.data.growthInfo,
          shopGrowthPercent: shopGrowth,
          incomeGrowthPercent: incomeGrowth
        }
      })
    },
  }
})
